#include <stdio.h>

void *my_memcpy(void *dest, const void *src, size_t n)
{
    char *d = (char *)dest;
    const char *s = (const char *)src;
    for (int i = 0; i < n; i++)
    {
        d[i] = s[i];
    }
    return dest;
}

void *my_memmove(void *dest, const void *src, size_t n)
{
    char *d = (char *)dest;
    const char *s = (const char *)src;
    if (s < d)
    {
        for (int i = n - 1; i >= 0; i--)
        {
            d[i] = s[i];
        }
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            d[i] = s[i];
        }
    }
    return dest;
}

char *my_strstr(char *str1, const char *str2)
{
    if (*str2 == '\0')
    {
        return str1;
    }
    for (char *h = str1; *h != '\0'; h++)
    {
        char *h1 = h;
        const char *h2 = str2;
        while (*h1 != '\0' && *h2 != '\0' && *h1 == *h2)
        {
            ++h1;
            ++h2;
        }
        if (*h2 == '\0')
        {
            return (char *)h;
        }
    }
    return NULL;
}

int main()
{
    // char arr1[] = "hello\n";
    // char arr2[] = "abcdefgaaaaaaaaaaaa\n";
    // // my_memcpy(arr1, arr2, 7);
    // //my_memmove(arr2 + 5, arr2 + 3, 4);
    // char*arr3 = my_strstr("hello world\n","world\n");

    // printf("%s", arr3);

    int a[] = {1, 2, 3, 4};
    printf("%d\n", sizeof(a));
    printf("%d\n", sizeof(a + 0));
    printf("%d\n", sizeof(*a));
    printf("%d\n", sizeof(a + 1));
    printf("%d\n", sizeof(a[1]));
    printf("%d\n", sizeof(&a));
    printf("%d\n", sizeof(*&a));
    printf("%d\n", sizeof(&a + 1));
    printf("%d\n", sizeof(&a[0]));
    printf("%d\n", sizeof(&a[0] + 1));
    return 0;
}
